package com.itheima.algorithm.dynamicprogramming;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <h3>括号生成 - 动态规划</h3>
 */
public class Leetcode22 {
    public static void main(String[] args) {
        Leetcode22 leetcode22 = new Leetcode22();
        System.out.println(leetcode22.generateParenthesis(3));
    }

    public List<String> generateParenthesis(int n) {
        ArrayList<String>[] dp = new ArrayList[n + 1];
        dp[0] = new ArrayList<String>(Arrays.asList(""));
        dp[1] = new ArrayList<String>(Arrays.asList("()"));
        for (int j = 2; j < n + 1; j++) {
            dp[j] = new ArrayList<>();
            for (int i = 0; i < j; i++) {
                System.out.printf("(%d,%d)\t", i, j - 1 - i);
                for (String k1 : dp[i]) {
                    for (String k2 : dp[j - 1 - i]) {
                        dp[j].add("(" + k1 + ")" + k2);
                    }
                }
            }
            System.out.println();
        }
        return dp[n];
    }
}
